docker rm -f mywordpress wp-mysql || true

MYSQL_IMAGE=index.csphere.cn/microimages/mysql
docker run -d --name wp-mysql -e MYSQL_ROOT_PASSWORD=wppass $MYSQL_IMAGE
sleep 2

PHPUNIT_IMAGE=index.csphere.cn/microimages/phpunit
if ! docker run --rm --link wp-mysql:mysql --entrypoint=/app/docker-entrypoint-test.sh -v $PWD:/app $PHPUNIT_IMAGE; then
  docker rm -f wp-mysql
  #exit 1
fi

docker rm -f wp-mysql

docker run -d --name wp-mysql -e MYSQL_ROOT_PASSWORD=wppass $MYSQL_IMAGE
sleep 2

TAG=`echo $GIT_COMMIT|cut -c1-7`
IMAGE=train/wordpress:$TAG
docker run -d --name mywordpress --link wp-mysql:mysql -P $IMAGE

PORT=`docker port mywordpress|grep '80/tcp'|cut -d: -f2`

echo "http://your-ip:$PORT"

